home *** CD-ROM | disk | FTP | other *** search
- Path: news.eunet.cz!usenet
- From: Borivoj Kostka <kostka@tovek.cz>
- Newsgroups: comp.lang.c++
- Subject: Re: How big is the 0
- Date: 19 Feb 1996 09:54:52 GMT
- Organization: EUnet Czechia (a customer)
- Message-ID: <4g9hdc$cjj@news.eunet.cz>
- NNTP-Posting-Host: sherlock.dial-up.cz
-
- anh@kuhub.cc.ukans.edu writes:
- >
- > Hello,
- >
- > In C, anytime I need to do a null pointer check I would do this:
- >
- > MyType *p;
- >
- > if(p==(MyType*)0)
- > bla;
- >
- > The new operator supposedly return a 0 upon failure. Can I rely on the
- > compiler to make sure the 0 is as big as the size of the pointer? For
- > example, ALPHA's pointers are 64 bits long which is different from the 32 bits
- > int.
- >
- > Thank-you.
- >
- > Anh
- The new operator NEVER returns a 0. It throws an exception. You have to
- catch this exception. For example (in BC 4.5)
-
- try {
- buf = new char[DYNA_BIG_BUF];
- }
- catch (xalloc) {
- MessageBox("Not enough memory", "Exception Error", MB_ICONEXCLAMATION|MB_OK);
- ...
- }
-
- In BC there is some way, how to make new operator to return
- NULL upon failure. Check documentation.
-
-